/**
 *
 */
package com.storm.lib.type;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.storm.lib.util.ExceptionUtil;
import com.storm.lib.util.FileUtil;
import com.storm.lib.util.PropertyUtil;



/**
 * 类功能: 系统常量类
 * @author johnny
 * @version 2010-10-28
 */
public class SystemType {


	/**
	 * 用户数据库名
	 */
	public static final String USER_DB_NAME="rpg_user_db";
	/**
	 * 用户数据库名
	 */
	public static final String GAME_DB_NAME="rpg_game_db";

	/**
	 * 日志数据库
	 */
	public static final String LOG_DB_NAME="rpg_log_db";

	public static  String DATABASE_URL =null;

	public static  String DATABASE_USERNAME = null;

	public static  String DATABASE_PASSWORD = null;

	public static  String DATABASE_DRIVERCLASSNAME = null;
	/**
	 * 语言 1.中文 2.英文
	 */
	public static final Integer LANGUAGE_TYPE=2;
	public static final Integer LANGUAGE_TYPE_CN=1;
	public static final Integer LANGUAGE_TYPE_EN=2;

	public static final String OPENFIRE_DB_NAME = null;
	/**
	 * 运行状态
	 */
	public static final short SERVER_STATUS_RUN = 1;

	/**
	 * 停止状态
	 */
	public static final short SERVER_STATUS_STOPPED = 2;

//	public static final Class[] GAMECLASS= new Class[]{ItemPo.class,TaskPo.class,NpcPo.class,AreaPo.class,ScenePo.class,UnitPo.class,ConditionPo.class,FarmPlantPo.class,EffectPo.class,SkillPo.class,BufferPo.class,LevelUpPo.class};
	/**
	 * 确认消息框
	 */
	public static final int MESSAGE_CONFIRM = 1;

	/**
	 * TIP消息框
	 */
	public static final int MESSAGE_TIP = 2;

	/**
	 * 右下弹出的消息框
	 */
	public static final int MESSAGE_POPUP = 3;
	/**
	 * 农场田地加速倍数
	 */
	public static Integer VAR_FARM_FIELD_GROW_FAST_TIMES = 360;
	/**
	 * 农场树加速倍数
	 */
	public static int VAR_FARM_TREE_GROW_FAST_TIMES = 5760;

	/**
	 * 部队恢复加速
	 */
	public static long VAR_ARMY_RECOVER_FAST_TIMES = 50;

	/**
	 * 最大兵种刷新数量
	 */
	public static int VAR_UNIT_MAX_TIMES = 1;
	/**
	 * Destanation
	 */
	public static final String PUSH_DESTINATION = "pushDes";
	public static final String MD5_CLIENT_KEY = "rpggame";
	public static final Integer RESPONSE_SUCCESS = 1;
	public static final Integer RESPONSE_FAILED = -1;
	public static final String GAMECLASS = null;

	/**
	 * 服务器唯一标识码
	 */
	public static String SERVER_UID = "未设定的唯一码";

	/**
	 * 当前UnitId索引
	 */
	public static int CURRENT_UNIT_INDEX = 0;

	/**
	 * 服务器名字
	 */
	public static String SERVER_NAME = "服务器名未设置";

	/**
	 * 多久离线剔除
	 */
	public static int AUTO_KICK_OFFLINE_USER_SECONDS = 60;
	public static String CHAT_DOMAIN="未设定的域名";
	public static String CHAT_GAMEGM_PASSWORD="未设定的聊天账号密码";

	/**
	 * 中央主机ip
	 */
	public static String CENT_HOST="未设定中央主机IP";
	/**
	 * 本地RMI连接地址
	 */
	public static String LOCAL_RMI_HOST="本地地址";
	/**
	 * 本地RMI连接端口
	 */
	public static Integer LOCAL_RMI_PORT=0;

//	public static List<PlatFormBean> platformBeans = new ArrayList<PlatFormBean>();
	/**
	 * 文件上传地址
	 */
	public static String DATA_UPLOAD_PATH="";
	/**
	 * 表数据备份地址
	 */
//	public static String DATA_BACKUP_PATH="";
	/**
	 * 玩家数据打包保存地址
	 */
//	public static String DATA_ROLE_PATH="";
	/**
	 * 客户端国际文本上传保存地址
	 */
//	public static String DATA_CLIENT_PATH="";

//	public static String DATA_GENERATOR_PATH = "";
	/**
	 * 战报保存地址
	 */
	public static String DATA_REPORT_PATH = "";

	//****************************************日志清理相关参数***************************************//
	public static String VAR_DATA_BATTLE = "VAR_DATA_BATTLE";
	public static String VAR_DATA_LOG = "VAR_DATA_LOG";
	public static String VAR_DATA_MAIL = "VAR_DATA_MAIL";
	public static String VAR_DATA_TIMER = "VAR_DATA_TIMER";
	public static String CLEAN_TIME = "CLEAN_TIME";
	public static String KEEP_TIME = "KEEP_TIME";

	public static String VAR_WRITE_DBLOG;
	public static String VAR_PRINT_EXCEPTION;
	public static String VAR_SEND_EXPECTION;
	/**
	 * 战斗信息清理时间
	 */
	public static int[] VAR_DATA_BATTLE_CLEAN_TIME = {};
	/**
	 * 战斗信息保留时间
	 */
	public static int VAR_DATA_BATTLE_KEEP_TIME = 0;
	/**
	 * 日志信息清理时间
	 */
	public static int[] VAR_DATA_LOG_CLEAN_TIME = {};
	/**
	 * 日志信息保留时间
	 */
	public static int VAR_DATA_LOG_KEEP_TIME = 0;
	/**
	 * 邮件信息清理时间
	 */
	public static int[] VAR_DATA_MAIL_CLEAN_TIME = {};
	/**
	 * 邮件信息保留时间
	 */
	public static int VAR_DATA_MAIL_KEEP_TIME = 0;
	/**
	 * 定时器信息清理时间
	 */
	public static int[] VAR_DATA_TIMER_CLEAN_TIME = {};
	/**
	 * 定时器信息保留时间
	 */
	public static int VAR_DATA_TIMER_KEEP_TIME = 0;
	/**
	 * 删除角色
	 */
	public static int PROCESS_ROLE_TYPE_DELETE = 1;
	/**
	 * 打包玩家数据(玩家自己的操作)
	 */
	public static int PROCESS_ROLE_TYPE_BALE_BY_PLAYER = 2;
	/**
	 * 打包玩家数据(系统的操作)
	 */
	public static int PROCESS_ROLE_TYPE_BALE_BY_SYSTEM = 3;
	/**
	 * 导入玩家数据
	 */
	public static int PROCESS_ROLE_TYPE_IMPORT_ROLE_INFO = 4;

	/**
	 * 英文
	 */
	public static String LANGUAGE_PREFIX_ENGLISH="en-us";

	/**
	 * 简体中文
	 */
	public static String LANGUAGE_PREFIX_SIMPLIFIED_CHINESE="zh-cn";


	public static Integer CHAT_PORT = 0;

	public static Integer CHAT_POLICYPORT=0;
	/**
	 * ip
	 */
	public static String CHAT_IP="未设定的聊天IP";

	/**
	 * 运营接口页面
	 */
	public static String OPERATION_URL="未设定";

	/**
	 * 初始状态
	 */
	public static Integer THREAD_STATE_DEFAULT = 0;
	/**
	 * 运行状态
	 */
	public static Integer THREAD_STATE_WAIT = 1;
	/**
	 * 结束状态
	 */
	public static Integer THREAD_STATE_RUN = 2;
	/**
	 * 请求间隔时间
	 */
	public static long REQUEST_SPACING_INTERVAL = 100;

	public static String MD5KEY;
	public static String resource_path;;
	
	//public static boolean 
	/**
	 * 注册人数
	 */
	public static int OPERATION_TYPE_REGISTER = 1;
	/**
	 * 玩家等级到达
	 */
	public static int OPERATION_TYPE_ROLE_ACHIEVE = 2;
	/**
	 * 武将等级到达
	 */
	public static int OPERATION_TYPE_HERO_ACHIEVE = 3;
	/**
	 * 充值送礼
	 */
	public static int OPERATION_TYPE_GIVE_GIFT = 4;

	static{
		File propertiesFile = FileUtil.getFileByClassPath(Constant.SYSTEM_PROPERTIES_RELATED_PATH);
		Properties properties = new Properties();
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(propertiesFile);
			properties.load(fis);
		} catch (Exception e) {
			ExceptionUtil.throwInvalidParamException();
		}
		finally{
			try {
				fis.close();
			} catch (IOException e) {
				ExceptionUtil.processPrintException(e);
			}
		}
//		SystemType.SERVER_NAME = PropertyUtil.getValueIfNotNull(properties,"server.name",SystemType.SERVER_NAME);
//		SystemType.SERVER_UID = PropertyUtil.getValueIfNotNull(properties,"server.uid",SystemType.SERVER_UID);
		SystemType.SERVER_UID = PropertyUtil.getValueIfNotNull(properties,"server.uid",SystemType.SERVER_UID);
		SystemType.CENT_HOST = PropertyUtil.getValueIfNotNull(properties,"center.host",SystemType.CENT_HOST);
//		SystemType.DATA_BACKUP_PATH = PropertyUtil.getValueIfNotNull(properties,"backup.path",SystemType.DATA_BACKUP_PATH);
//		SystemType.DATA_ROLE_PATH = PropertyUtil.getValueIfNotNull(properties, "role.path", SystemType.DATA_ROLE_PATH);
//		SystemType.DATA_CLIENT_PATH = PropertyUtil.getValueIfNotNull(properties, "client.path", SystemType.DATA_CLIENT_PATH);
		SystemType.DATA_UPLOAD_PATH = PropertyUtil.getValueIfNotNull(properties, "upload.path", SystemType.DATA_UPLOAD_PATH);
//		SystemType.DATA_GENERATOR_PATH = PropertyUtil.getValueIfNotNull(properties, "generator.path", SystemType.DATA_GENERATOR_PATH);
		SystemType.LOCAL_RMI_HOST = PropertyUtil.getValueIfNotNull(properties, "local.rmi.host", SystemType.LOCAL_RMI_HOST);
		SystemType.LOCAL_RMI_PORT = Integer.valueOf(PropertyUtil.getValueIfNotNull(properties, "local.rmi.port", SystemType.LOCAL_RMI_PORT));
		SystemType.DATABASE_URL = PropertyUtil.getValueIfNotNull(properties, "database.url", SystemType.DATABASE_URL);
		SystemType.DATABASE_USERNAME = PropertyUtil.getValueIfNotNull(properties, "database.username", SystemType.DATABASE_USERNAME);
		SystemType.DATABASE_PASSWORD = PropertyUtil.getValueIfNotNull(properties, "database.password", SystemType.DATABASE_PASSWORD);
		SystemType.DATABASE_DRIVERCLASSNAME = PropertyUtil.getValueIfNotNull(properties, "database.driverClassName", SystemType.DATABASE_DRIVERCLASSNAME);
		SystemType.DATA_REPORT_PATH = PropertyUtil.getValueIfNotNull(properties, "report.path", SystemType.DATA_REPORT_PATH);
		FileUtil.ifNotExistMkdir();
	}

	public static boolean writeDBLog(){
		if("true".equals(SystemType.VAR_WRITE_DBLOG)){
			return true;
		}
		return false;
	}

	public static boolean printException(){
		if("true".equals(SystemType.VAR_PRINT_EXCEPTION)){
			return true;
		}
		return false;
	}

	public static boolean sendException(){
		if("true".equals(SystemType.VAR_SEND_EXPECTION)){
			return true;
		}
		return false;
	}
}
